#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<stack>
using namespace std;


class Solution {
public:
    int regionsBySlashes(vector<string>& grid) {
        int n = grid.size();
        int num = 0;
        int sumSize = 4*n*n;
        //融合每个单元格中的小格
        for(int i = 0;i<n;++i){
            for(int j = 0;j<n;++j){
                int a = num+1;
                parents[a] = a;
                int b = num +2;
                parents[b] = b;
                int c = num+3;
                parents[c] = c;
                int d = num+4;
                parents[d] = d;
                num = d;
                if(grid[i][j] == ' '){
                    unionSet(a,b);
                    unionSet(b,c);
                    unionSet(c,d);
                    sumSize = sumSize-3;
                }
                else if(grid[i][j]=='/'){
                    unionSet(a,b);
                    unionSet(c,d);
                    sumSize = sumSize-2;
                }
                else if(grid[i][j]=='\\'){
                    unionSet(a,d);
                    unionSet(b,c);
                    sumSize = sumSize-2;
                }
            }
        }
        //融合单元格
        int start = 3;
        int end = 4*n*n;
        int i = 1;
        while(start<=end){
            if(start+4*(n-1)+2<=4*n*n){
                if(!isSameSet(start,start+4*(n-1)+2)){
                    unionSet(start,start+4*(n-1)+2);
                    sumSize -=1;
                }
            }
            if(start+1+2<=4*n*n&&i<n){
                if(!isSameSet(start+1,start+1+2)){
                    unionSet(start+1,start+1+2);
                    sumSize -=1;
                }
            }
            start = start+4;
            if(i==n){
                i=1;
            }
            else{
                i = i+1;
            }
        }
        return sumSize;
    }
    int findFather(int a){
        stack<int> path;
        while(parents[a]!=a){
            path.push(a);
            a = parents[a];
        }
        while(!path.empty()){
            parents[path.top()] = a;
            path.pop();
        }
        return a;
    }

    bool isSameSet(int a,int b){
        return findFather(a)==findFather(b);
    }
    
    void unionSet(int a,int b){
        if(!isSameSet(a,b)){
            int afather = findFather(a);
            int bfather = findFather(b);
            parents[afather] = bfather;
        }
    }

public:  
    map<int,int> parents;
};


int main(){
    vector<string> grid = {" /\\"," \\/","\\  "};
    Solution S;
    int size = S.regionsBySlashes(grid);
    cout<<size<<endl;
}